<template>
  <transition name="slide-fade">
    <div class="top-btn" @click="toTop" v-show="showTop">
      <i class="iconfont icon-top"></i>
      <p>顶部</p>
    </div>
  </transition>
</template>

<script>
export default {
  props: ["scrollY"],
  computed: {
    showTop() {
      if (this.scrollY > document.body.clientHeight) {
        return true;
      } else {
        return false;
      }
    }
  },
  methods: {
    toTop() {
      this.$emit("toTop");
    }
  },
  mounted() {}
};
</script>

<style lang="less" scoped>
.top-btn {
  width: 0.42rem;
  height: 0.42rem;
  position: fixed;
  right: 0.2rem;
  bottom: 0.64rem;
  z-index: 999;
  opacity: 0.9;
  background-color: white;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  p {
    font-size: 0.1rem;
    color: #333;
  }
}

.slide-fade-enter-active {
  transition: all 0.8s;
}
.slide-fade-leave-active {
  transition: all 0.3s;
}
.slide-fade-enter,
.slide-fade-leave-to {
  transform: translateY(100%);
  opacity: 0;
}
</style>

